package com.ppm.server.user.controller;

import com.github.pagehelper.PageHelper;
import com.ppm.common.base.constant.BaseConstant;
import com.ppm.common.base.dto.ResultDTO;
import com.ppm.common.base.entity.UserInfo;
import com.ppm.server.base.controller.BaseController;
import com.ppm.server.user.dto.UserInfoDTO;
import com.ppm.server.user.dto.UserQueryConditionDTO;
import com.ppm.server.user.service.*;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(value = "用户相关控制器", tags = "用户相关控制器")
@RestController
@RequestMapping("/user")
public class UserInfoController extends BaseController {

    @Autowired
    UserInfoService userInfoService;

    @PutMapping("/saveUser")
    @ApiOperation(value = "新增用户", notes = "新增用户")
    public ResultDTO saveUser(@RequestBody UserInfo userInfo) {
        return userInfoService.saveUser(userInfo);
    }

    /**
     * 分页获得会员信息列表
     * @return
     */
    @PostMapping("/getUserList")
    @ApiOperation(value = "分页获得会员信息列表", notes = "分页获得会员信息列表")
    @ApiResponses({@ApiResponse(code = 200,message = "OK",response = UserInfoDTO.class)})
    public ResultDTO getUserList(@ApiParam("页数，不传默认1")
                                 @RequestParam(value = "pageNum", defaultValue = BaseConstant.PAGE_DEFAULT_INDEX, required = false) Integer pageNum,
                                 @ApiParam("页大小，不传默认10")
                                 @RequestParam(value = "pageSize", defaultValue = BaseConstant.PAGE_DEFAULT_SIZE, required = false) Integer pageSize,
                                 @RequestBody(required = false) UserQueryConditionDTO userQueryConditionDTO) {
        PageHelper.startPage(pageNum, pageSize);
        return generatePage(userInfoService.getUserList(userQueryConditionDTO));
    }

}
